package ua.com.jpy.entity;

import java.util.Date;
import java.util.List;

import javax.annotation.Generated;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.bson.types.ObjectId;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

import ua.com.jpy.entity.role.Role;

import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;

/**
 * @author LSD25
 *
 */
@Entity(noClassnameStored = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public abstract class AEntity implements IEntity {
	
	@Id
	private ObjectId id;
	
	@NotBlank(message = "Email does not has null or empty")
	@Size(min = 5, max = 20, message = "Length email has above 5 elements and less 20")
	@Pattern(regexp = "^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$", message = "Email can not be so")
	private String email;
	
	@NotBlank(message = "Login does not has null or empty")
//	@Valid
	@Pattern(regexp = "[A-Z]{1}[0-9]{3}", message = "Login can not be so")
	private String login;
	
	@NotBlank(message = "Firstname does not has null or empty")
//	@Valid
	@Pattern(regexp = "[A-Z]{1}[0-9]{3}", message = "Firstname can not be so")
	private String firstName;
	
	@NotBlank(message = "SecondName does not has null or empty")
//	@Valid
	@Pattern(regexp = "[A-Z]{1}[0-9]{3}", message = "SecondName can not be so")
	private String secondName;
	
	@NotBlank(message = "Password does not has null or empty")
	@Size(min = 8, max = 25, message = "Password has above 8 elements and less 25")
	private String password;
	
	@NotBlank(message = "Confirm password does not has null or empty")
	@Size(min = 8, max = 25, message = "Confirm password has above 8 elements and less 25")
	private String confirmPassword;
	
	@DateTimeFormat
	private Date lastVisit;
	
	private int countVisit;
	
	@DecimalMin(value = "0")
	private double money;
	
	@NotEmpty
	@Embedded
	private List<Role> roles;

	private boolean isActive;
	
	@NotBlank(message = "Password does not has null or empty")
	@Generated(value = { "ua.com.jpy.common.entity.AEntity" })
	private String confirmKey;
	
	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}
	
	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	public ObjectId getId() {
		return id;
	}

	public void setId(ObjectId id) {
		this.id = id;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSecondName() {
		return secondName;
	}

	public void setSecondName(String secondName) {
		this.secondName = secondName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getLastVisit() {
		return lastVisit;
	}

	public void setLastVisit(Date lastVisit) {
		this.lastVisit = lastVisit;
	}

	public int getCountVisit() {
		return countVisit;
	}

	public void setCountVisit(int countVisit) {
		this.countVisit = countVisit;
	}

	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	public String getConfirmKey() {
		return confirmKey;
	}

	public void setConfirmKey(String confirmKey) {
		this.confirmKey = confirmKey;
	}
	
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
}
